//切换省份更新市
function changeProvince(obj) {
	//切换省份时将分页设置为第1页
	var pageNumber = 1;
	//省
	var province = $(obj).val();
	//市
	var cityOptions = '';
	$("#selectEndNum").find('input[name="'+ province +'"]').each(function(idx){
		if(idx == 0) {
			$("#selectedCity").attr("value", $(this).val());
		}
		cityOptions += '<option value="'+ $(this).val() +'">'+ $(this).val() +'</option>';
	});
	$("#secondCity").empty().append(cityOptions);
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			$("#phoneNumInfo").empty().append(data);
		}
	});
}

//切换城市事件
function changeCity(obj) {
	$("#selectedCity").attr("value", $(obj).val());
	//切换城市时将分页设置为第1页
	var pageNumber = 1;
	//获取城市
	var city = $(obj).val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			$("#phoneNumInfo").empty().append(data);
		}
	});
}

//号码排序
function orderNum() {
	//获取当前页数
	var pageNumber = $(".pageNumber-hidden").attr("value");
	var pageSize = 20;
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取价格当前排序类型
	var priceOrderType = $("#priceOrder").attr("name");
	
	var orderType = '';
	if($("#numOrder").hasClass("zm_cn_sorta")) {
		$("#numOrder").removeClass("zm_cn_sorta").addClass("zm_cn_sort");
		$("#numOrder").attr("name", "numDefaultDesc");
		orderType += 'numAsc';
	}else{
		$("#numOrder").removeClass("zm_cn_sort").addClass("zm_cn_sorta");
		orderType += 'numDesc';
		$("#numOrder").attr("name", "numDefaultAsc");
	}
	//获取号码当前排序类型
	var numOrderType = $("#numOrder").attr("name");
	//alert("numOrderType:"+numOrderType+" priceDefaultType:"+priceOrderType);

	$.ajax({
		url: "orderByNumberAndPrice.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			$("#phoneNumInfo").empty().append(data);
		}
	});
}
//价格排序
function orderPrice() {
	//获取城市
	var selectedCity = $("#selectedCity").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码当前排序类型
	var numDefaultType = $("#numOrder").attr("name");
	var orderType = '';
	if($("#priceOrder").hasClass("zm_cn_sorta")) {
		$("#priceOrder").removeClass("zm_cn_sorta").addClass("zm_cn_sort");
		$("#priceOrder").attr("name", "priceDefaultDesc");
		orderType += 'priceAsc';
	}else{
		$("#priceOrder").removeClass("zm_cn_sort").addClass("zm_cn_sorta");
		$("#priceOrder").attr("name", "priceDefaultAsc");
		orderType += 'priceDesc';
	}
	//alert("numDefaultType:"+numDefaultType);
	$.ajax({
		url: "orderPhoneNumByType.jhtml",
		type: "POST",
		data: {city:selectedCity, phoneNum:startNum, orderType:orderType, defaultType:numDefaultType},
		dataType: "html",
		cache: false,
		async: false,
		success: function(data) {
			
		}
	});
}

//切换号段事件
function changeNum(obj) {
	$(".zm_inputText_none").attr("value", "");
	$("#selectedNum").attr("value", $(obj).val());
	//切换号段时将分页设置为第1页
	var pageNumber = 1;
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			$("#phoneNumInfo").empty().append(data);
		}
	});
	
}

//搜索4位尾号
function searchEndNum() {
	var regx = /^\d{4}$/;
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	if(!regx.test(endNum)){
		$.message("error", "请输入4位数字!");
		return;
	}
	//切换号段时将分页设置为第1页
	var pageNumber = 1;
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			$("#phoneNumInfo").empty().append(data);
		}
	});
}

//选择号码
function selectedPhoneNum(obj) {
	$(".zm_num_info").find("li").removeClass("on");
	$(obj).addClass("on");
	//所选号码
	var selectedPhoneNum = $(obj).find("p.zm_theNum").html();
	$("#hidden_selectedPhoneNum").attr("value", selectedPhoneNum);
}

//确定选号
function submitSelectedPhoneNum() {
	var selectedPhoneNum = $("#hidden_selectedPhoneNum").val();
	var productId = $("#hidden_productId").val();
	//alert(productId);
	window.location.href = "submitSelectedPhoneNumByProduct.jhtml?selectedPhoneNum=" + selectedPhoneNum + "&productId="+ productId +"";
}






